package com.smt.modules.app.utils;

import com.smt.common.utils.Constant;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * 获取当前请求的request的参数的用户id
 *
 * @author zhangyi
 * @date 2018/10/10 11:21
 */
public class RequestUtils {

    public static Integer getRequest(){
        RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
        String userId = request.getParameter(Constant.USER_KEY);
        if(userId == null){
            return 0;
        }
        return Integer.parseInt(userId);
    }
}
